package com.heima.schedule.client;

import com.heima.api.feign.IScheduleFeginClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO
 *
 * @Author mr.zhao
 * @Date 2025/6/22 23:10
 */
@RestController
public class ScheduleClient implements IScheduleFeginClient {
	@Autowired
	private TaskService taskService;

	/**
	 * 添加任务的方法
	 *
	 * @param task
	 */
	@PostMapping("/api/v1/task/add")
	@Override
	public ResponseResult saveTask(Task task) {
		return ResponseResult.okResult(taskService.addTask(task));
	}

	/**
	 * 按照类型和优先级拉取
	 * @param type
	 * @param priority
	 * @return
	 */
	@GetMapping("/api/v1/task/{type}/{priority}")
	@Override
	public ResponseResult poll(@PathVariable("type")int type, @PathVariable("priority")int priority){
		return ResponseResult.okResult(taskService.poll(type, priority));
	}

	/**
	 * 删除任务
	 *
	 * @param taskId
	 * @return
	 */
	@GetMapping("/api/v1/task/{taskId}")
	@Override
	public ResponseResult cancelTask(long taskId) {
		return ResponseResult.okResult(taskService.deleteTask(taskId));
	}
}
